package com.yellowpage.wf.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.wf.dao.AttachmentInstanceDao;
import com.yellowpage.wf.data.AttachmentInstance;

public class AttachmentInstanceServiceImpl extends BaseServiceImpl implements AttachmentInstanceService {
	  private AttachmentInstanceDao attachmentInstanceDao;
	
	  public void setAttachmentInstanceDao(AttachmentInstanceDao attachmentInstanceDao) {
		this.attachmentInstanceDao = attachmentInstanceDao;
	}
	/* White generate Method */ 
	  public void saveAttachmentInstance(AttachmentInstance attachmentInstance)
	  {
		  attachmentInstanceDao.save(attachmentInstance);
	  }
	  public void delete(List deleteList){
		  attachmentInstanceDao.remove(deleteList);
	  }
	  public List<Map> getAttachmentInstanceVersion(Long instanceId,Long attachmentId){
			String sql = "select max(wai.version) as version from wf_attachment_instance wai where " +
					" wai.workflow_instance_id = "+instanceId.toString()+
					" and wai.attachment_id = "+attachmentId.toString();

			QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(sql);
			List<Map> resultList = this.baseDao.query(sqlAssistant, new HashMap());
			return resultList;
		}
	  public List<Map> getAttachmentInstanceHis(Long attachmentId){
		  String sql = "select t.version,t.resource_id,wr.name as fname,wr.type,wr.dir " +
		  		" from wf_attachment_instance t,wf_resource wr " +
		  		" where t.resource_id = wr.resource_id " +
		  		" and t.attachment_id = "+attachmentId.toString();

		  QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(sql);
		  List<Map> resultList = this.baseDao.query(sqlAssistant, new HashMap());
		  return resultList;
	  }
}	